package com.tpyule.tpclass.service.impl;

import com.tpyule.tpclass.dao.ChapterDao;
import com.tpyule.tpclass.entity.pojo.Chapter;
import com.tpyule.tpclass.service.ChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.UUID;

/**
 * @author zzz
 * @version 1.0
 * @date 2020/3/29 13:31
 */
@Service
public class ChapterServiceImpl implements ChapterService {
    @Autowired
    ChapterDao chapterDao;
    @Override
    public Chapter addChapter(Chapter chapter) {
        chapter.setChapterId(UUID.randomUUID().toString().toUpperCase());
        int result=chapterDao.addChapter(chapter);
        if(result!=0){
            return chapter;
        }else
            return null;
    }

    @Override
    public String updateChapter(Chapter chapter) {
        int result = chapterDao.updateChapter(chapter);
        if(chapter.getRemove() == 0) {
            chapterDao.updateBigChapter(chapter);
        }
        if(result!=0){
            return "success";
        }else {
            return "error";
        }
    }

    @Override
    public Chapter getLastChapter(String courseId) {
        return chapterDao.getLastChapter(courseId);
    }

    @Override
    public List<Chapter> getListChapter(String courseId) {
        return chapterDao.getListChapter(courseId);
    }
}
